package com.lyj.sc.tianchi;

import java.util.Stack;

/**
 * @program: code-random
 * @description:
 * @author: lyj
 * @create: 2022-07-14 16:30
 * @version: 1.0
 * @Modifier By:
 **/
public class MinStack {
    Stack<Integer> stack = null;
    Stack<Integer> minstack = null;
    public MinStack() {
        stack = new Stack<>();
        minstack = new Stack<>();
    }

    public void push(int val) {
        if(minstack.isEmpty()){
            minstack.push(val);
        }else {
            Integer peek = minstack.peek();
            if(peek<val){
                minstack.push(peek);
            }else {
                minstack.push(val);
            }
        }
        stack.push(val);
    }

    public void pop() {
        minstack.pop();
        stack.pop();
        return;
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minstack.peek();
    }
}
